package com.ylc.proxy4;

import com.ylc.proxy4.AOP.AOP;
import com.ylc.proxy4.Service.Service;

/**
 * @Author: ylc
 * @Description:
 * @Date Created in 2022-07-18 15:18
 */
public class Agent implements Service {
    public Service target;
    public AOP aop;

    public Agent(Service target, AOP aop) {
        this.target = target;
        this.aop = aop;
    }

    @Override
    public void buy() {
        try {
            //切面功能
            aop.before();//哪个实现类来了,调用哪个实现类的功能
            //业务功能
            target.buy();
            //切面功能
            aop.after();
        } catch (Exception e) {
            aop.exception();
        }
    }
}
